package com.osce.basic.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.csce.domain.entity.basic.TabAssetOutOrder;
import com.csce.domain.entity.basic.vo.TabAssetOutOrderDTO;
import com.osce.common.utils.bean.BeanUtils;
import com.osce.interfaces.basic.ITabAssetOutOrderService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.osce.common.annotation.Log;
import com.osce.common.core.controller.BaseController;
import com.osce.common.core.entity.AjaxResult;
import com.osce.common.enums.BusinessType;
import com.osce.common.utils.poi.ExcelUtil;
import com.osce.common.core.page.TableDataInfo;

/**
 * 耗材出库Controller
 *
 * @author hdj
 * @since 2025-11-16
 */
@RestController
@RequestMapping("/basic/order")
public class TabAssetOutOrderController extends BaseController {

    @Resource
    private ITabAssetOutOrderService tabAssetOutOrderService;

/**
 * 查询耗材出库列表
 */
@PreAuthorize("@ss.hasPermi('basic:order:list')")
@GetMapping("/list")
    public TableDataInfo list(TabAssetOutOrder tabAssetOutOrder) {
        startPage();
        List<TabAssetOutOrder> list = tabAssetOutOrderService.selectTabAssetOutOrderList(tabAssetOutOrder);
        return getDataTable(list);
    }

    /**
     * 导出耗材出库列表
     */
    @PreAuthorize("@ss.hasPermi('basic:order:export')")
    @Log(title = "耗材出库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TabAssetOutOrder tabAssetOutOrder) {
        List<TabAssetOutOrder> list = tabAssetOutOrderService.selectTabAssetOutOrderList(tabAssetOutOrder);
        ExcelUtil<TabAssetOutOrder> util = new ExcelUtil<TabAssetOutOrder>(TabAssetOutOrder. class);
        util.exportExcel(response, list, "耗材出库数据");
    }

    /**
     * 获取耗材出库详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:order:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(tabAssetOutOrderService.selectTabAssetOutOrderById(id));
    }

        /**
     * 获取耗材出库申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:order:query')")
    @GetMapping(value = "/order/{id}")
    public AjaxResult getOrderInfo(@PathVariable("id") String id) {
        return success(tabAssetOutOrderService.selectTabAssetOutOrderByOrderId(id));
    }

    /**
     * 新增耗材出库
     */
    @PreAuthorize("@ss.hasPermi('basic:order:add')")
    @Log(title = "耗材出库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TabAssetOutOrder tabAssetOutOrder) {
        return toAjax(tabAssetOutOrderService.insertTabAssetOutOrder(tabAssetOutOrder));
    }

    /**
     * 修改耗材出库
     */
    @PreAuthorize("@ss.hasPermi('basic:order:edit')")
    @Log(title = "耗材出库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TabAssetOutOrder tabAssetOutOrder) {
        return toAjax(tabAssetOutOrderService.updateTabAssetOutOrder(tabAssetOutOrder));
    }

    /**
     * 删除耗材出库
     */
    @PreAuthorize("@ss.hasPermi('basic:order:remove')")
    @Log(title = "耗材出库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(tabAssetOutOrderService.deleteTabAssetOutOrderByIds(ids));
    }
}
